//
//  MXNetworkManager+Extension.swift
//  微博
//
//  Created by LoadingMx on 2017/3/27.
//  Copyright © 2017年 LoadingMx. All rights reserved.
//

import Foundation

// MARK: - 封装新浪微博的网络请求
extension MXNetworkManager {
    
    func statusList(completion:@escaping (_ list: [[String: AnyObject]]?, _ isSuccess: Bool)->()) {
        
        // 用 网络工具 加载微博数据
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json"
        let params = ["access_token" : "2.00WR8pjGx8_VuC40c34039e60daPB3"]
        request(URLString: urlString, parameters: params as [String : AnyObject]) { (json, isSuccess) in
            
            // 从 json 中获取 statuses 字典数组
            // 如果 as? 失败, result = nil
            // FIXME: json 特别注意类型转型 -> MXNetworkManager.swift 中相应关系
            let result = json?["statuses"] as? [[String: AnyObject]]
            completion(result, isSuccess)
        }
    }
}
